package com.tongxin.van.frameworkcanary.utils;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;

import com.blankj.utilcode.util.CacheUtils;
import com.blankj.utilcode.util.ToastUtils;

import com.tongxin.van.frameworkcanary.MainActivity;
import com.tongxin.van.frameworkcanary.base.ActivityManager;
import com.tongxin.van.frameworkcanary.dailog.ConfirmDialog;
import com.tongxin.van.frameworkcanary.http.HttpUtil;

/**
 *
 * author: VanyLiu
 * email: 13212674795@163.com
 * description:公共工具类
 *
**/
public class CommonDialogUtils {
    /**
     * 打电话，显示打电话对话框
     */
    public static void callPhone(Activity activity, String phone) {
        new ConfirmDialog(activity)
                .setMessage(phone)
                .setConfirmButton("呼叫")
                .setOnConfirmListener(dialog -> {
                    Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phone));
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    activity.startActivity(intent);
                }).show();
    }

    /**
     * 清除缓存
     */
    public static void clearCache(Activity activity) {
        new ConfirmDialog(activity)
                .setMessage("是否清除缓存？")
                .setConfirmButton("清除")
                .setOnConfirmListener(dialog -> {
                    CacheUtils.getInstance().clear();
                    dialog.dismiss();
                    ToastUtils.showShort("清除成功");
                }).show();
    }

    /**
     * 退出登录，三个端都可以调用
     */
    public static void exitLogin(Activity activity) {
        new ConfirmDialog(activity)
                .setMessage("是否退出登录？")
                .setConfirmButton("确定")
                .setOnConfirmListener(dialog -> {
                    HttpUtil.clearCookies();
//                    XGPushManager.delAllAccount(activity);
                    dialog.dismiss();
                    ActivityManager.getManager().popAllActivity();
                    activity.startActivity(new Intent(activity, MainActivity.class));
                }).show();
    }
}
